!function (t, l) {
    t.ClientService = function () {
        this.ServerUrl = "https://gitee.com/bzsometest", this.yiclearAppUrl = this.ServerUrl + "", this.loadingSubscriptions = Object.create(null)
    }, t.ClientService.prototype = {
        loadYiclearSubscriptions: function (o, l) {
            var a = t.SubscriptionFilter, e = t.Prefs.localSubscriptionsPath;
            this._executeRequestAsync(e, "text/xml", function (e) {
                var t = e.responseXML;
                if (t && t.getElementsByTagName) {
                    for (var i = [], n = t.getElementsByTagName("subscription"), s = 0; s < n.length; s++) {
                        var r = a.fromXml(n[s]);
                        r.filterId = n.length + 110 + s, r.lastUpdateTime = (new Date).getTime(), i.push(r)
                    }
                    o(i)
                } else l(e, "empty response")
            }, l)
        }, loadFilterRules: function (e, t, i, n) {
            this.loadFilterRulesBySubscriptionUrl(e, i, n)
        }, loadFilterRulesBySubscriptionUrl: function (n, s, r) {
            if (!(n in this.loadingSubscriptions)) {
                this.loadingSubscriptions[n] = !0;
                var o = this;
                l.StringUtils.startWith(n, "local/") && (n = l.ext.getURL("ad_clear/raw/master/ChinaList2.0.txt")), this._executeRequestAsync(n, "text/plain", function (e) {
                    if (delete o.loadingSubscriptions[n], 200 === e.status) {
                        var t = (e.responseText || "").trim();
                        if (0 !== t.length) {
                            var i = t.split(/[\r\n]+/);
                            0 === i[0].indexOf("[") && i.shift(), s(i)
                        } else r(e, "filter rules missing")
                    } else r(e, "wrong status code: " + e.status)
                }, function (e, t) {
                    delete o.loadingSubscriptions[n], r(e, t)
                })
            }
        }, _executeRequestAsync: function (e, t, i, n) {
            var s = new XMLHttpRequest, r = e;
            l.StringUtils.contains(e, "://") || (r = "http://" + e);
            try {
                if (s.open("GET", r), s.setRequestHeader("Content-type", t), s.setRequestHeader("Pragma", "no-cache"), s.overrideMimeType(t), s.mozBackgroundRequest = !0, s.timeout = 15e3, i && (s.onload = function () {
                    i(s)
                }), n) {
                    var o = function () {
                        n(s)
                    };
                    s.onerror = o, s.onabort = o, s.ontimeout = o
                }
                s.send(null)
            } catch (e) {
                n && n(s, e)
            }
        }, yiclearFilterUpdate: function (n) {
            var e = function (e) {
                var t = e.responseText, i = JSON.parse(t);
                n(i)
            }.bind(this);
            this._executeRequestAsync(this.yiclearAppUrl + "/FiltersInfo.json", "text/plain", e, function (e) {
                n(e)
            })
        }
    }
}(yiclearAPI, vAPI);